//
//  SingleProductView.m
//  ChunLaiZhuangClient
//
//  Created by zouzhisheng on 16/3/13.
//  Copyright © 2016年 CLZ. All rights reserved.
//

#import "SingleProductView.h"

@implementation SingleProductView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
-(id)initWithFrame:(CGRect)frame{
    self= [super initWithFrame:frame];
    if (self) {
        
        self.productImageView=[[UIImageView alloc] initWithFrame:CGRectMake(10, 0,self.width-20, 170)];
        self.productImageView.contentMode=UIViewContentModeScaleAspectFit;
        self.productImageView.clipsToBounds=YES;
        [self addSubview:self.productImageView];
        self.productInforLabel=[[UILabel alloc] initWithFrame:CGRectMake(14,self.productImageView.bottom+5,self.width-28,40)];
        self.productInforLabel.textAlignment=NSTextAlignmentCenter;
        self.productInforLabel.font=[UIFont systemFontOfSize:14];
        self.productInforLabel.numberOfLines=0;
        self.productInforLabel.textColor=[UIColor colorWithHexString:@"a5a5a"];
        [self addSubview:self.productInforLabel];
        self.priceLabel=[[UILabel alloc] initWithFrame:CGRectMake(14,self.productInforLabel.bottom,self.width-28, 30)];
        self.priceLabel.textAlignment=NSTextAlignmentCenter;
        self.priceLabel.bottom=self.height-3;
        [self addSubview:self.priceLabel];
        self.discountImageView=[[UIImageView alloc] initWithFrame:CGRectMake(self.width-50, 2, 44, 26)];
        self.discountImageView.image=[UIImage imageNamed:@"pic_zhekou"];
        self.disLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 40, 26)];
        self.disLabel.textColor=[UIColor whiteColor];
        self.disLabel.font=[UIFont systemFontOfSize:14];
        self.disLabel.textAlignment=NSTextAlignmentCenter;
        [self.discountImageView addSubview:self.disLabel];
        [self addSubview:self.discountImageView];
        self.discountImageView.hidden=YES;
        
        
        self.sellOutImageView=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 214/2, 214/2)];
        self.sellOutImageView.image=[UIImage imageNamed:@"sellout"];
        [self addSubview:self.sellOutImageView];
        self.sellOutImageView.hidden=YES;
        self.sellOutImageView.center=CGPointMake(self.width/2, self.height/2-30);
        
    }
    return self;
}
-(void)setProductModel:(id)productModel{
    if ([productModel isKindOfClass:[ProductDetailModel class]]) {
        ProductDetailModel *model=(ProductDetailModel*)productModel;
        [self.productImageView sd_setImageWithURL:[NSURL URLWithString:model.image] placeholderImage:nil];
        self.productInforLabel.text=model.name;
        self.priceLabel.text=model.price_new;
        
    }
    if ([productModel isKindOfClass:[ProductListDetailModel class]]) {
        ProductListDetailModel *model=(ProductListDetailModel*)productModel;
        [self.productImageView sd_setImageWithURL:[NSURL URLWithString:model.image] placeholderImage:nil];
        self.productInforLabel.text=model.name;
        self.priceLabel.text=model.price;
        if (model.discount.length>0) {
            self.discountImageView.hidden=NO;
            self.disLabel.text=model.discount;
            
        }
        if ([model.quantity intValue]==0 && model.quantity) {
            self.sellOutImageView.hidden=NO;
        }else{
            self.sellOutImageView.hidden=YES;
        }
        if (!model.quantity && model.in_stock) {
            if ([model.in_stock intValue]==0) {
                self.sellOutImageView.hidden=NO;
            }else{
                self.sellOutImageView.hidden=YES;
            }
        }
        
        
    }
    if ([productModel isKindOfClass:[SingleProductModel class]]) {
        SingleProductModel *model=(SingleProductModel*)productModel;
        [self.productImageView sd_setImageWithURL:[NSURL URLWithString:model.image] placeholderImage:nil];
        self.productInforLabel.text=model.name;
        self.priceLabel.text=model.price;
        if ([model.quantity intValue]==0 && model.quantity) {
            self.sellOutImageView.hidden=NO;
        }else{
            self.sellOutImageView.hidden=YES;
        }

    }

    
    
}
@end
